package com.leetcode.algorithm.y22.m06;

import java.util.Arrays;

/**
 * 1608. 特殊数组的特征值
 * 
 * https://leetcode.cn/problems/special-array-with-x-elements-greater-than-or-equal-x/
 * 
 * @author jie.deng
 *
 */
class Question1608Solution01 {

	public int specialArray(int[] nums) {
		Arrays.sort(nums);
		int len = nums.length;
		for (int x = 1; x < len; x++) {
			if (nums[len - x] >= x && nums[len - x - 1] < x) {
				return x;
			}
		}
		if (nums[0] >= len) {
			return len;
		}
		return -1;
	}

}